﻿using Biomedica.Graphics;
using Biomedica.Nui.ui;
using NuiDicomPlayer;
using NuiDicomPlayer.Controls;
using NuiDicomPlayer.Subviews;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DicomViewerAdvanced.VirtualMouse
{
    delegate void UpdateProgrssBox();
    /// <summary>
    /// Interaction logic for mouseImposter.xaml
    /// </summary>
    public partial class mouseImposter : UserControl
    {
        private bool enable;
        public bool Enabled
        {
            set
            {
                enable = true;
                if (enable)
                {
                    this.Visibility = Visibility.Visible;
                }
                else
                {
                    this.Visibility = Visibility.Collapsed;
                }
            }
            get
            {
                return enable;
            }
        }
        public NuiControl OwnerControl { get; set; }
        Storyboard sb = new Storyboard();
        DoubleAnimation d;
        public Point Location;
        private int State;
        public mouseImposter()
        {
            InitializeComponent();
           
        }
        private void invokeItemClicked()
        {
            ResetTimer();
            if (OwnerControl != null && NuiControl.OnHandFiredEventRoutedEvent!=null) OwnerControl.RaiseEvent(new RoutedEventArgs(NuiControl.OnHandFiredEventRoutedEvent, this));  
           
        }
        public void StartTimer()
        {
            d = new DoubleAnimation(0, this.ActualWidth,new Duration(TimeSpan.FromMilliseconds(2000)));
            d.Completed += d_Completed;
            progressbox.BeginAnimation(Rectangle.WidthProperty, d);
         
        }
        void d_Completed(object sender, EventArgs e)
        {
            invokeItemClicked();
        }
        public void ResetTimer()
        {
            progressbox.BeginAnimation(Rectangle.WidthProperty, null);
         
        }

        public void UpdateHand(Biomedica.Graphics.Vector2 v, Canvas canvas,SubviewBase mainWindow)
        {
            Canvas.SetLeft(this, v.X);
            Canvas.SetTop(this, v.Y);

            HitTest(mainWindow);

        }
        public virtual void HitTest(SubviewBase mainWindow)
        {
            foreach (NuiControl btn in UserControlTransition.FindVisualChildren<NuiControl>(mainWindow))
                btn.HandHitTest(Location);
        }
       
    }
}
